#ifndef VIDEOWIDGET_H
#define VIDEOWIDGET_H

#include <QWidget>
#include <phonon/videoplayer.h>
#include <phonon/mediaobject.h>
#include <QKeyEvent>
#include <QTimer>

class VideoWidget : public Phonon::VideoPlayer
{
    Q_OBJECT
public:
    explicit VideoWidget(QWidget *parent = 0);


    Q_INVOKABLE void playlocalfile(QString file);
    Q_INVOKABLE void refreshTime(int ms);
    Q_INVOKABLE void reload();
    Q_INVOKABLE inline qint64 totalTime(){
        //qDebug()<<"total:"<<this->VideoPlayer::totalTime();
        return this->mediaObject()->totalTime();
    }
    Q_INVOKABLE inline void seek(qint64 ms){Phonon::VideoPlayer::seek(ms);}
    //Q_INVOKABLE inline void stop(){VideoPlayer::stop();}

    Q_INVOKABLE inline bool isPlaying(){return VideoPlayer::isPlaying();}
    Q_INVOKABLE inline bool isPaused(){return VideoPlayer::isPaused();}

signals:
    void position(qint64 time_ms);
    void totalTimeChanged(qint64 time_ms);
    void seekableChanged(bool isSeekable);
    void playStateRaise();//Phonon::State oldState , Phonon::State newState);
    void pauseStateRaise();


    void resizeEventSglRedirect();
    void moveEventSglRedirect();
    void focusInEventSglRedirect();
    void focusOutEventSglRedirect();
    void showEventSglRedirect();
    void hideEventSglRedirect();
    void keyPressEventSglRedirect(QKeyEvent * e);

protected :
    void resizeEvent( QResizeEvent *);
    void moveEvent(QMoveEvent *);
    void hideEvent(QHideEvent *e);
    void showEvent ( QShowEvent * e);
    void focusInEvent(QFocusEvent *e);
    void focusOutEvent(QFocusEvent *e);
    void keyPressEvent ( QKeyEvent * e );

private slots:
    void onSeekableReload();
    void onStateChanged(Phonon::State oldState , Phonon::State newState);

private :
    //QTimer * m_timer;
    QString m_localfile;
    int tickInterval;
    qint64 seekForReload;
};

#endif // VIDEOWIDGET_H
